import React from 'react'
import {getTicketApi} from '../../api/ticket'
import { useLoaderData } from 'react-router-dom'
import MyavBr from './components/MyavBr'
import MyDate from './components/MyDate'
import styles from './css/deail.module.css'
import TicketCard from './components/TicketCard'
import TicketCollapse from './components/TicketCollapse'


const Deail = () => {

    const {info}=useLoaderData()

  return (
    <div className={styles.box}>
       <MyavBr title={info.trainNo}/>
       <MyDate />

       <TicketCard {...info}/>
       <TicketCollapse {...info}/>
    </div>
  )
}

export default Deail


export const loader= async({params,request})=>{
    console.log('执行了详情 loader');

    const id=params.id
    const url=new URL(request.url)
    const obj=Object.fromEntries(url.searchParams)

    const {data:res}=await getTicketApi(id,obj)
    console.log(res);
    
    return {info:res}
}
